package com.jd.yao.controller;

import com.alibaba.fastjson.JSON;
import com.jd.yao.controller.common.ResPage;
import com.jd.yao.controller.common.YaoBuyerSettings;
import com.jd.yao.controller.dao.YaoBuyerSettingsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping(value = "/test")
public class BaseController {
    @Autowired
    YaoBuyerSettingsMapper yaoBuyerSettingsMapper;

    /**
     * ok
     * @param id
     */
    @RequestMapping(value = "/get")
    public void add(Long id){
        YaoBuyerSettings findSettings = yaoBuyerSettingsMapper.getById(id);
        System.out.println(JSON.toJSONString(findSettings));
    }

    /**
     * ok
     */
    @RequestMapping(value = "add")
    public void insert(){
        YaoBuyerSettings buyerSettings = this.getData();
        yaoBuyerSettingsMapper.insert(buyerSettings);
    }

    /**
     * ok
     * @param id
     */
    @RequestMapping(value = "/del")
    public void del(Long id){
        yaoBuyerSettingsMapper.delById(id);
    }

    /**
     * ok
     * @param id
     */
    @RequestMapping(value = "/update")
    public void update(Integer id){
        YaoBuyerSettings buyerSettings = this.getData();
        buyerSettings.setId(id);
        yaoBuyerSettingsMapper.updateSelective(buyerSettings);
    }

    @RequestMapping(value = "/query")
    public void query(Long companyId, Integer currentPage){
        YaoBuyerSettings query = new YaoBuyerSettings();
        query.setCompanyId(companyId);
        ResPage resPage = new ResPage();
        resPage.setCurrentPage(currentPage);
        List<YaoBuyerSettings> yaoBuyerSettings = yaoBuyerSettingsMapper.queryPage(query, resPage);
        System.out.println(JSON.toJSONString(yaoBuyerSettings));
    }

    @RequestMapping(value = "/queryCount")
    public void queryCount(Long companyId){
        YaoBuyerSettings query = new YaoBuyerSettings();
        query.setCompanyId(companyId);
        Integer cnt = yaoBuyerSettingsMapper.queryPageCount(query);
        System.out.println(cnt);
    }

    public YaoBuyerSettings getData(){
        YaoBuyerSettings buyerSettings = new YaoBuyerSettings();
        buyerSettings.setAggrState(true);
        buyerSettings.setAggrStatus(true);
        buyerSettings.setBId(222222L);
        buyerSettings.setBrandId(22222L);
        buyerSettings.setChannel(22222);
//        buyerSettings.setCompanyBody("公司主体2222");
        buyerSettings.setCompanyId(22222L);
        buyerSettings.setCreator("lantianxiang2222");
        buyerSettings.setDistributeOrg("分配机构222222");
        buyerSettings.setIsIncrErp(true);
        buyerSettings.setModifier("lantianxiang222222");
        buyerSettings.setYn(true);
        buyerSettings.setVenderId(22222L);
        return buyerSettings;
    }
}
